package com.zhangxu.microservice.employee.web.controller.feign;

import com.zhangxu.microservice.common.result.CommonResult;
import com.zhangxu.microservice.employee.api.response.EmployeeApiDTO;
import com.zhangxu.microservice.employee.biz.service.EmployeeBizService;
import com.zhangxu.microservice.employee.domain.dto.EmployeeDTO;
import com.zhangxu.microservice.employee.web.mapstruct.EmployeeConverter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/feign")
@Tag(name = "用户管理(feign)")
@RequiredArgsConstructor
public class EmployeeFeignController {

    private final EmployeeBizService employeeBizService;
    private final EmployeeConverter employeeConverter;

    /**
     * 根据用户名查询用户信息（内部 Feign 调用）
     */
    @GetMapping("employees/{employeeId}")
    public CommonResult<EmployeeApiDTO> getById(@PathVariable("employeeId") Long employeeId) {
        EmployeeDTO employeeDTO = employeeBizService.getById(employeeId);
        return CommonResult.success(employeeConverter.toEmployeeDTO(employeeDTO));
    }

    /**
     * 根据用户名查询用户信息（内部 Feign 调用）
     */
    @GetMapping("employees/listByIds")
    public CommonResult<List<EmployeeApiDTO>> listByIds(@RequestParam("employeeIds") List<Long> employeeIds) {
        List<EmployeeDTO> employeeDTOs = employeeBizService.listByIds(employeeIds);
        return CommonResult.success(employeeConverter.toEmployeeDTOList(employeeDTOs));
    }

}
